import 'package:pixelyear/sql/ColorSqlUtils.dart';
import 'package:pixelyear/sql/NoteSqlUtils.dart';
import 'package:pixelyear/sql/RecordSqlUtils.dart';
import 'package:sqflite/sqflite.dart';
import 'package:path/path.dart';

class Sql {
  static final String recordName = "record";
  final String record = "create table if not exists " +
      recordName +
      "(_id integer primary key autoincrement," +
      "color integer ,year integer,month integer,day integer , textColor integer , mood integer)";

  static final String noteName = "note";
  final String note = "create table if not exists " +
      noteName +
      "(_id integer primary key autoincrement," +
      "date text," +
      "note text" +
      ")";

  static final String colorName = "color";
  final String color = "create table if not exists " +
      colorName +
      "(_id integer primary key autoincrement," +
      "color integer," +
      "msg text," +
      "position integer" +
      ")";

  Database _db;

  Future open() async {}



  Future<Database> getDb() async {
    if (_db == null || !_db.isOpen) {
      String databasesPath = await getDatabasesPath();
      String path = join(databasesPath, 'yxs.db');
      // open the database
      _db = await openDatabase(path, version: 1,
          onCreate: (Database db, int version) async {
        // When creating the db, create the table
        await db.execute(record);
        await db.execute(note);
        await db.execute(color);
      });
    }
    return _db;
  }

  static ColorSqlUtils getColorUtils() {
    return ColorSqlUtils.instance;
  }

  static NoteSqlUtils getNoteUtils() {
    return NoteSqlUtils.instance;
  }

  static RecordSqlUtils getRecordUtils() {
    return RecordSqlUtils.instance;
  }

  close() async {
    if (_db != null && _db.isOpen) await _db.close();
  }
}
